package com.scvtc.controller.comprehensive;

import com.scvtc.domain.ResResult;
import com.scvtc.domain.dto.comprehensive.ComprehensivePolicyDocumentDto;
import com.scvtc.domain.vo.PageVo;
import com.scvtc.service.comprehensive.ComprehensivePolicyDocumentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Digits;
import java.util.List;

import static com.scvtc.constants.SystemCheckedConstants.PAGE_CURRENT_ERROR;
import static com.scvtc.constants.SystemCheckedConstants.PAGE_SIZE_ERROR;
import static com.scvtc.constants.SystemConstants.PAGE_CURRENT;
import static com.scvtc.constants.SystemConstants.PAGE_SIZE;

/**
 * 综合模块(ComprehensivePolicyDocument)表控制层
 *
 * @author yiFei
 * @since 2022-04-13 17:38:26
 */
@Api(tags = "综合模块(ComprehensivePolicyDocument)")
@RestController
@RequestMapping("comprehensivePolicyDocument")
public class ComprehensivePolicyDocumentController {
    /**
     * 综合模块(ComprehensivePolicyDocment)对象
     */
    @Autowired
    private ComprehensivePolicyDocumentService comprehensivePolicyDocumentService;


    @GetMapping("/list")
    @ApiOperation("显示政策文件")
    @PreAuthorize("hasAuthority('policy:document:list')")
    public ResResult<PageVo<List<ComprehensivePolicyDocumentDto>>> getAllPolicyDocument(
            @Digits(integer = 5, fraction = 1, message = PAGE_CURRENT_ERROR) @RequestParam(defaultValue = PAGE_CURRENT) Long current,
            @Digits(integer = 3, fraction = 0, message = PAGE_SIZE_ERROR) @RequestParam(defaultValue = PAGE_SIZE) Long size,
            ComprehensivePolicyDocumentDto comprehensivePolicyDocumentDto) {
        return comprehensivePolicyDocumentService.getAllPolicyDocument(current, size, comprehensivePolicyDocumentDto);
    }

    @PostMapping("/")
    @ApiOperation("添加单个政策文件")
    @PreAuthorize("hasAuthority('policy:document:add')")
    public ResResult<?> addPolicyDocument(@RequestBody ComprehensivePolicyDocumentDto comprehensivePolicyDocumentDto) {
        return comprehensivePolicyDocumentService.addPolicyDocument(comprehensivePolicyDocumentDto);
    }

    @PutMapping("/")
    @ApiOperation("修改单个政策文件")
    @PreAuthorize("hasAuthority('policy:document:update')")
    public ResResult<?> updatePolicyDocument(@RequestBody ComprehensivePolicyDocumentDto comprehensivePolicyDocumentDto) {
        return comprehensivePolicyDocumentService.updatePolicyDocument(comprehensivePolicyDocumentDto);
    }

    @DeleteMapping("/")
    @ApiOperation("删除单个政策文件")
    @PreAuthorize("hasAuthority('policy:document:delete')")
    public ResResult<?> deletePolicyDocument(Long id) {
        return comprehensivePolicyDocumentService.deletePolicyDocument(id);
    }

    @DeleteMapping("/multiple")
    @ApiOperation("删除多个政策文件")
    @PreAuthorize("hasAuthority('policy:document:delete')")
    public ResResult<?> deleteMultiplePolicyDocument(Long[] ids) {
        return comprehensivePolicyDocumentService.deleteMultiplePolicyDocument(ids);
    }
}

